/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package clases;

import java.awt.HeadlessException;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author Juan
 */
public class Sql {

    ResultSet r;
    CallableStatement st;
    PreparedStatement ps;
    Statement stm;
    Connection cn;
    private DataInputStream dis;
    private DataOutputStream dos;
    
    public String EntradaA(String Usuario,int Maquina){
        try{
        Conexion c = new Conexion();
        cn=c.conectar();
        ps=cn.prepareCall("{Call EntradaA(?,?)}");
        ps.setString(1, Usuario);
        ps.setInt(2, Maquina);
        int res=ps.executeUpdate();
        if(res==1){
            //JOptionPane.showMessageDialog(null, "Registro Exitoso");
            return "E";
        }
        }catch(SQLException | HeadlessException e){
            //JOptionPane.showMessageDialog(null, "Usuario no Registrado en la Maquina "+ Maquina);
            return "R";
        }
        return null;
    }
    
    public String SalidaA(int Maquina){
        try {
            Conexion c = new Conexion();
            cn=c.conectar();
            ps=cn.prepareCall("{Call SalidaA(?)}");
            ps.setInt(1, Maquina);
            int res=ps.executeUpdate();
            if(res==1){
                return "S";
            }
        } catch (SQLException | HeadlessException e) {
            return "R2";
        }
        return null;
    }
    
    public String EmtradaM(String Usuario, int maquina){
        try{
        Conexion c = new Conexion();
        cn=c.conectar();
        ps=cn.prepareCall("{Call EntradaM(?,?)}");
        ps.setString(1, Usuario);
        ps.setInt(2, maquina);
        int res=ps.executeUpdate();
        if(res==1){
            //JOptionPane.showMessageDialog(null, "Registro Exitoso");
            return "E";
        }
        }catch(SQLException | HeadlessException e){
            //JOptionPane.showMessageDialog(null, "Usuario no Registrado en la Maquina "+ Maquina);
            return "R";
        }
        return null;
    }
    
    public String SalidaM(int Maquina){
        try {
            Conexion c = new Conexion();
            cn=c.conectar();
            ps=cn.prepareCall("{Call SalidaM(?)}");
            ps.setInt(1, Maquina);
            int res=ps.executeUpdate();
            if(res==1){
                return "S";
            }
        } catch (SQLException | HeadlessException e) {
            return "R2";
        }
        return null;
    }
}
